$(function() {
	$('.dispatch').on('click',function(){
		layer.msg('派车成功');
	})
	var showlocation = {
		offset: function(othis) {
			var type = othis.data('type'),
				text = othis.text();

			layer.open({
				type: 1,
				area: ['800px', '800px'],
				title: false,
				offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
					,
				id: 'layerDemo' + type //防止重复弹出
					,
				content: '<div id="showlocation" style="width:99%;height:99%;margin:1%"></div>',
				btn: ['确认'],
				success: function(layero) {
					var btn = layero.find('.layui-layer-btn');
					//					layer.closeAll();
				},
				btn2: function() {
					layer.closeAll();
				},
				btnAlign: 'c' //按钮居中
					,
				shade: 0 //不显示遮罩
					,
				yes: function() {
					layer.closeAll();
				}
			});
		}
	};
	$('i.am-icon-map').on('click', function() {
		console.log(1)
		var othis = $(this),
			method = othis.data('method');
		showlocation[method] ? showlocation[method].call(this, othis) : '';
		var map = new AMap.Map('showlocation', {
			resizeEnable: true,
			zoom: 11,
			center: [118.57, 24.82]
		});
	})
	
	$('.dispatch-number').on('DOMNodeInserted',function(){
       console.log(1)
    })
	
	
	
	
	var origin = []
	var map = new AMap.Map('carmap', {
			resizeEnable: true,
			zoom: 11,
			center: [118.57, 24.82]
	});

	//构造路线导航类
	var driving = new AMap.Driving({
		map: map,
		//		panel: "panel"
	});
	$.ajax({
		type: "POST",
		url: "http://121.199.45.196/Api/CarModel/lists",
		data: "phone=18700781005&pwd=sznanshan",
		success: function(res) {
			console.log(res)
		},
		error: function(res) {
			console.log(res)
		}
	});

	AMapUI.loadUI(['overlay/SimpleMarker'], function(SimpleMarker) {
		var iconStyles = SimpleMarker.getBuiltInIconStyles('fresh');
        departure = new SimpleMarker({
					//普通文本
					iconStyle: iconStyles[2],
					 //自定义图标节点(img)的属性
			//          iconStyle: {
			//
			//              src: '//webapi.amap.com/theme/v1.3/markers/b/mark_b.png',
			//              style: {
			//                  width: '20px',
			//                  height: '30px'
			//              }
			//          },
					//图标文字
					iconLabel: {
						//A,B,C.....
						innerHTML: "起",
						style: {
							//颜色, #333, red等等，这里仅作示例，取iconStyle中首尾相对的颜色
							color: '#fff'
						}
					},
					map: map,
					position:[118.6799, 24.7286],
					cont: {
						drivername: 1,
						begin: 1,
						end: 1
					}
				});
		destination = new SimpleMarker({
					//普通文本
					iconStyle: iconStyles[2],

					//图标文字
					iconLabel: {
						//A,B,C.....
						innerHTML: "终",
						style: {
							//颜色, #333, red等等，这里仅作示例，取iconStyle中首尾相对的颜色
							color: '#fff'
						}
					},
					map: map,
					position:[118.692123, 24.756079],
					cont: {
						drivername: 1,
						begin: 1,
						end: 1
					}
				});
		var origin = [{
				orderid: 1,
				path: [
					[118.5780, 24.8350],
					[118.6260, 24.8311]
				],
				driver: "黄师傅",
				number:'闽C2000',
				phone:13805966464,
				discount:213123123,
				driverno:234234,
				carry:8
			},
			{
				orderid: 1,
				path: [
					[118.42, 24.82],
					[118.68, 24.85]
				],
				driver: "蔡师傅",
				number:'闽C2000',
				phone:13805966464,
				discount:234234234,
				driverno:1325125,
				carry:10
			},
			{
				orderid: 1,

				path: [
					[118.548635, 24.818144],
					[118.638348, 24.883766]
				],
				driver: "蔡师傅",
				number:'闽C2000',
				phone:13805966464,
				discount:345345345,
				driverno:125,
				carry:2
			},
			{
				orderid: 1,
				path: [
					[118.6799, 24.7286],
					[118.7000, 24.7292]
				],
				driver: "蔡师傅",
				number:"闽C2000",
				phone:13805966464,
				discount:45645645,
				driverno:125325,
				carry:4
			},
			{
				orderid: 1,
				path: [
					[118.613599, 24.714986],
					[118.692123, 24.756079]
				],
				driver: "蔡师傅",
				number:'闽C2000',
				phone:13805966464,
				discount:67867867,
				driverno:25125,
				carry:4
			},
		];
		var arr=[];
		for(var i=0;i<origin.length;i++){
			var car = new SimpleMarker({
					//普通文本
					  iconStyle: {
			
			              src: '{$static_dir}/assets/img/car.png',
			              style: {
			                  width: '20px',
			                  height: '30px'
			              }
			          },

					//图标文字
//					iconLabel: {
//						//A,B,C.....
//						innerHTML: "车",
//						style: {
//							//颜色, #333, red等等，这里仅作示例，取iconStyle中首尾相对的颜色
//							color: '#fff'
//						}
//					},
					map: map,
					position:origin[i].path[0],
					cont: {
						driver: origin[i].driver,
						num:origin[i].number,
						phone:origin[i].phone,
						discount:origin[i].discount,
						driverno:origin[i].driverno,
						carry:origin[i].carry
					}
				});
				arr.push(car)
			
		}	
		for(var j=0;j<arr.length;j++){
			var index=j
			arr[j].on('click',function(){
				
				for(var index in this) {
					for(var index1 in this[index]) {
						if(index1 == "cont") {
							$('.driver').html(this[index].cont.driver)
							$('.driver').next('input').val('this[index].cont.driver')
							$('.driver_phone').html(this[index].cont.phone)
							$('.driver_phone').next('input').val('this[index].cont.phone')
							$('.car_id').html(this[index].cont.num)
							$('.car_id').next('input').val('this[index].cont.num')
							$('.discount').html(this[index].cont.discount)
							$('.discount').next('input').val('this[index].cont.discount')
							$('.carry').html(this[index].cont.carry)
							$('.carry').next('input').val('this[index].cont.carry')
							$('.driver_no').html(this[index].cont.driverno)
							$('.driver_no').next('input').val('this[index].cont.driverno')
						};
			
					};
				};
				
			})
		}
	});
	
	
	
	
})